package cn.nicklemay.interview.designpattern.Decorator;

public class TrollDecorator implements Troll {
    private Troll decorated;

    public TrollDecorator(Troll decorated) {
        this.decorated = decorated;
    }

    @Override
    public void attack() {
        decorated.attack();
        System.out.println("The troll swings at you with a club!");
    }

    @Override
    public int getAttackPower() {
        return decorated.getAttackPower() + 10;
    }

    @Override
    public void fleeBattle() {
        decorated.fleeBattle();
    }

    public static void main(String[] args) {
        // simple troll
        Troll troll = new SimpleTroll();
        troll.attack(); // The troll tries to grab you!
        troll.fleeBattle(); // The troll shrieks in horror and runs away!

        // change the behavior of the simple troll by adding a decorator
        troll = new TrollDecorator(troll);
        troll.attack(); // The troll tries to grab you! The troll swings at you with a club!
        troll.fleeBattle(); // The troll shrieks in horror and runs away!
    }
}
